﻿package com.wongoing.sys.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wongoing.base.BaseServiceImpl;
import com.wongoing.base.PageResult;
import com.wongoing.sys.dao.SysCodeDao;
import com.wongoing.sys.model.SysCode;
import com.wongoing.sys.model.ext.SysCodeExt;
import com.wongoing.sys.service.SysCodeService;

@Service("sysCodeService")
@Transactional
public class SysCodeServiceImpl extends BaseServiceImpl<SysCode> implements SysCodeService {
	private SysCodeDao dao;

	@Autowired
	public void setDao(SysCodeDao dao) {
		super.setDao(dao);
		this.dao = dao;
	}
	
	/**
	 * 功能说明：获取码表分页数据的最终页面展现数据
	 * 修改说明：
	 * @author wuzq
	 * @date 2017年10月13日 下午8:38:23
	 * @param pageResult 分页查询对象，包含查询条件
	 * @return 返回分页查询对象，包含页面数据
	 */
	public PageResult<SysCodeExt> getSysCodeListPageResult(PageResult<SysCodeExt> pageResult) {
		pageResult.getParam().put("offset", pageResult.getPageSize() * (pageResult.getPageCurrent() - 1));
		pageResult.getParam().put("limit", pageResult.getPageSize());
		if (!"".equals(pageResult.getOrderField())) { pageResult.getParam().put("orderColumn", pageResult.getOrderField()); }
		pageResult.getParam().put("orderTurn", pageResult.getOrderDirection());
		List<SysCodeExt> data = this.dao.getSysCodeListByParam(pageResult.getParam());
		pageResult.setList(data);
		int totalSize = this.dao.countOfSysCodeListByParam(pageResult.getParam());
		pageResult.setTotal(totalSize);
		return pageResult;
	}

	/**
	 * 功能说明：获取退款码名称
	 * 修改说明：
	 * @author 吴兆强
	 * @date 2018年3月16日 上午9:17:27
	 * @param param
	 * @return
	 */
	public List<SysCodeExt> getAllChoosedCodeListByParam(Map<String, Object> param) {
		return this.dao.getAllChoosedCodeListByParam(param);
	}

	@Override
	public List<SysCode> searchCodeData(SysCode sysCode)throws Exception {
		sysCode.setStatus("0");
		Map<String, Object> whereMap = new HashMap<String, Object>();
		whereMap.put("status", 0);
		whereMap.put("codeType", sysCode.getCodeType());
		whereMap.put("orderColumn", "SeqIdx");
		List<SysCode> codeList = dao.getByParam(whereMap);
		return codeList;
	}
	
}
